﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using YArchitech.LIB;

namespace YJKOpeningCommon.Public
{
	public partial class ConfigDataBaseForm : System.Windows.Forms.Form
	{
		public ConfigDataBaseForm()
		{
			this.InitializeComponent();
		}

		public void SetFormLocation(string strXmlPath)
		{
			int x = 0;
			int y = 0;
			if (this.GetXmlData(strXmlPath, ref x, ref y))
			{
				this.m_point = new System.Drawing.Point(x, y);
				return;
			}
			this.m_point = new System.Drawing.Point(Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2);
		}

		private void ConfigDataBaseForm_Load(object sender, EventArgs e)
		{
			base.Location = this.m_point;
			//base.Icon = Resource.YArchitechIcon;
		}

		protected bool ReadHistoryRecordData()
		{
			return true;
		}

		protected bool SaveHistoryRecordData()
		{
			return true;
		}

		private bool GetXmlData(string strXmlPath, ref int locationX, ref int locationY)
		{
			bool result;
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				if (File.Exists(strXmlPath))
				{
					XmlReader xmlReader = XmlReader.Create(strXmlPath, new XmlReaderSettings
					{
						IgnoreComments = true
					});
					xmlDocument.Load(xmlReader);
					XmlNode xmlNode = xmlDocument.SelectSingleNode("HistoryData");
					locationX = Convert.ToInt32(xmlNode.Attributes["LocationX"].Value);
					locationY = Convert.ToInt32(xmlNode.Attributes["LocationY"].Value);
					xmlReader.Close();
					xmlDocument.Save(strXmlPath);
					result = true;
				}
				else
				{
					result = false;
				}
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		private Point m_point;

		private IContainer components;
	}
}
